package com.chenyun.system.vo;

import com.chenyun.system.model.SysDept;
import com.chenyun.system.model.SysMenu;
import com.chenyun.system.model.SysRegion;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author ruoyi
 */
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    private Object data;

    // 和label一致
    private String title;
    // 和id一致
    private String key;


    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() {

    }

    public TreeSelect(Long id, String label, Object data) {
        this.id = id;
        this.label = label;
        this.data = data;
        this.key=id.toString();
        this.title=label;
    }

    public TreeSelect(SysDept dept) {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.key=this.id.toString();
        this.title= this.label;
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenu menu) {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.key=this.id.toString();
        this.title= this.label;
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }


    public TreeSelect(SysRegion region) {

        SysRegion ndata = new SysRegion(region.getCode(), region.getName(), region.getPCode(), region.getLevel(), null);
        this.setId(Long.valueOf(region.getCode()));
        this.setLabel(region.getName());
        this.setData(ndata);
        this.key=this.id.toString();
        this.title= this.label;
        this.children = region.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
        this.key=id.toString();
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
        this.title=label;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public List<TreeSelect> getChildren() {
        return children;
    }

    public void setChildren(List<TreeSelect> children) {
        this.children = children;
    }

    public String getTitle() {
        return title;
    }

    public String getKey() {
        return key;
    }
}
